package com.superboo.core.service.impl;

import com.superboo.base.enums.ResultEnum;
import com.superboo.base.exception.GirlException;
import com.superboo.core.dao.GirlDao;
import com.superboo.core.domain.Girl;
import com.superboo.core.service.GirlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * GirlServiceImpl
 *
 * @author peiran zhang
 * @date 2017/3/20
 */
@Service("girlService")
public class GirlServiceImpl implements GirlService {

    @Autowired
    private GirlDao girlDao;

    @Override
    public Girl save(Girl girl) {
        girlDao.save(girl);
        return girl;
    }

    @Override
    public void getAge(Long id) throws GirlException {

        Girl girl = girlDao.findOne(id);
        Integer age = girl.getAge();

        if (age < 10) {
            throw new GirlException(ResultEnum.PRIMARY_SCHOOL);
        } else if (age > 10 && age < 16) {
            throw new GirlException(ResultEnum.MIDDLE_SCHOOL);
        }
    }

    @Override
    public Girl findOne(Long id) {
        return girlDao.findOne(id);
    }

    @Override
    public List<Girl> findAll() {
        return girlDao.findAll();
    }

}
